package vesion2.main;

import javax.swing.*;

public class RefreshThread extends Thread{
    private GamePanel panel;
    private int fre;
    private int time;
    public RefreshThread(JPanel panel, int frequency){
        super();
        this.panel=(GamePanel) panel;
        if(frequency>100||frequency<0)
            fre=40;
        else
            fre=frequency;

        time=1000/fre;
        setName("refresh");
    }

    @Override
    public void run() {
        super.run();
        while (true&&!panel.isStop()) {
            try {
                Thread.sleep(time);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            panel.repaint();
        }
    }
}
